package com.bingguo.interceptor;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import static com.bingguo.interceptor.returnBody.ERROR;

/**
 * 统一异常处理
 */
@ControllerAdvice
public class MyExceptionHandler {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public returnBody error(Exception e){
        return  returnBody.error().setCode(ERROR).setSuccess(false).setDesc(e.getMessage());
    }

}
